package org.yate.oa.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.yate.oa.model.LowBCKZQ;
import org.yate.oa.result.AjaxResult;
import org.yate.oa.result.WebResult;
import org.yate.oa.service.LowBCKZQService;
import org.yate.oa.utils.Pagination;

import com.alibaba.fastjson.JSONObject;

@Controller
@RequestMapping("/bckzq")
public class BCKZQController {
	@Resource
	private LowBCKZQService service;
	
	@RequestMapping("/page/list")
    private void pageList(HttpServletRequest req, HttpServletResponse resp) throws IOException{
        PrintWriter out = resp.getWriter();
        JSONObject json = new JSONObject();
        String page = req.getParameter("page");
        int pageIndex = 1;
        if (!StringUtils.isEmpty(page)) {
            pageIndex = Integer.parseInt(page);
        }
        Pagination<LowBCKZQ> p = this.service.getEntities(pageIndex, 10, new LowBCKZQ(), null, null);
       json.put("status", "200");
       json.put("data", p);
       out.println(json);
       out.flush();
       out.close();
    }

	@RequestMapping("/page/add")
	public String pageAdd(LowBCKZQ t) {
		if(t.getId()==null){
			this.service.add(t);
		}else{
			this.service.update(t);
		}
		return "/bckzq/list";
	}

	@RequestMapping("/page/modify")
	public ModelAndView pageModify(Long id) {
		Map<String,Object> map = new HashMap<String, Object>();
		LowBCKZQ t = this.service.getEntity(id);
		map.put("t", t);
		return WebResult.success("/bckzq/modify", map);
	}
	
	@RequestMapping("/remove")
	@ResponseBody
    public AjaxResult doDelete(Long id){
        service.remove(id);
        return AjaxResult.success();
    }
}
